#!/bin/bash

source ~/.bashrc
source ~/.bash_profile

export HADOOP_USER_NAME=hdfs

function clear_data() {
        name=$1
        integer_day=`echo "$name" | awk -F '=' '{print $2}'`
        check_day=`date -d '-15 days' '+%F'`
        integer_day_ts=`date -d $integer_day '+%s'`
        check_day_ts=`date -d $check_day '+%s'`
        if [ $integer_day_ts -lt $check_day_ts ];then
            # 跳过进入回收站直接删除
            hadoop fs -rm -r -skipTrash $name
            #echo $name
        else
            echo 'not enough 15 days'
        fi
}

#清理整数型旧指标数据
function delete_integer() {
        hadoop fs -ls /user/hdfs/integer_metric_data/store/ | grep "integer_metric_data" | awk '{print $NF}' | while read LINE
        do
                sleep 1
                clear_data $LINE
        done
}

#清理浮点型旧指标数据
function delete_float() {
        hadoop fs -ls /user/hdfs/float_metric_data/store/ | grep "float_metric_data" | awk '{print $NF}' | while read LINE
        do
                sleep 1
                clear_data $LINE
        done
}


delete_integer
delete_float
